import Vue from "vue";

// 校验是否是数字
const isNumber = (num) => {
	const reg = /^\d+$|^\d+[.]?\d+$/;
	return reg.test(num);
};

// 校验手机号
const isPhone = (num) => {
	const reg = /^1(345789)\d{9}$/;
	return reg.test(num);
};

// 校验身份证号
const isIdCard = (num) => {
	const reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
	return reg.test(num);
};

// 校验小数点后两位
const isTwoDecimal = (num) => {
	const reg = /^((0\.\d{1,2})|([1-9]\d*\.\d{1,2})|([1-9]+\d*)|0)$/;
	return reg.test(num);
};

// 校验正整数
const isInteger = (num) => {
	const reg = /^[+]?(\d+)$/;
	return reg.test(num);
};

Vue.prototype.isNumber = isNumber;
Vue.prototype.isIdCard = isIdCard;
Vue.prototype.isPhone = isPhone;
Vue.prototype.isTwoDecimal = isTwoDecimal;
Vue.prototype.isInteger = isInteger;